$.extend(validatePrompt, {
    mail: {
        onFocus: "邮箱作为登录账号，方便您接收订单通知，找回密码等",
        succeed: "",
        isNull: "请输入邮箱",
        error: {
            beUsed: "该邮箱已被使用，请更换其它邮箱",
            badFormat: "请输入有效的邮箱地址",
            badLength: "您填写的邮箱过长，邮箱地址只能在50个字符以内"
        }
    }
});
$.extend(
    validateFunction, {
        emReg_validate: function () {
            var emtype = $("#emType").val();
            if (emtype == "mobile") {
                $("#mobileInfo").jdValidate(validatePrompt.mobileInfo, validateFunction.mobileInfo, true);
                $("#pwd").jdValidate(validatePrompt.pwd, validateFunction.pwd, true);
                $("#pwd2").jdValidate(validatePrompt.pwd2, validateFunction.pwd2, true);
                $("#mobileCode").jdValidate(validatePrompt.mobileCode, validateFunction.mobileCode, true);
                return validateFunction.FORM_submit(["#mobileInfo", "#pwd", "#pwd2", "#mobileCode"]);
            } else {
                $("#mail").jdValidate(validatePrompt.mail, validateFunction.mail, true);
                $("#pwd").jdValidate(validatePrompt.pwd, validateFunction.pwd, true);
                $("#pwd2").jdValidate(validatePrompt.pwd2, validateFunction.pwd2, true);
                $("#authcode").jdValidate(validatePrompt.authcode, validateFunction.authcode, true);
                return validateFunction.FORM_submit(["#mail", "#pwd", "#pwd2", "#authcode"]);
            }

        },
        mail: function (option) {
            var email = strTrim(option.value);
            var format = validateRules.isEmail(email);
            var format2 = validateRules.betweenLength(email, 0, 50);
            if (!format) {
                validateSettings.error.run(option, option.prompts.error.badFormat);
            } else {
                if (!format2) {
                    validateSettings.error.run(option, option.prompts.error.badLength);
                } else {
                    if (!emailstate || emailold != email) {
                        if (emailold != email) {
                            emailold = email;
                            option.errorEle.html("<span style='color:#999'>检验中……</span>");
                            $.getJSON("../emReg/isEmailEngaged?email=" + escape(option.value) + "&r=" + Math.random(), function (date) {
                                if (date.success == 0) {
                                    validateSettings.succeed.run(option);
                                    emailstate = true;
                                } else {
                                    validateSettings.error.run(option, option.prompts.error.beUsed);
                                    emailstate = false;
                                }
                            })
                        }
                        else {
                            validateSettings.error.run(option, option.prompts.error.beUsed);
                            emailstate = false;
                        }
                    }
                    else {
                        validateSettings.succeed.run(option);
                    }
                }
            }
        }

    });
var isSubmit = false;
$("#pwd").bind("keyup",
    function () {
        validateFunction.pwdstrength();
    }).jdValidate(validatePrompt.pwd, validateFunction.pwd)
$("#pwd2").jdValidate(validatePrompt.pwd2, validateFunction.pwd2);
$("#mail").jdValidate(validatePrompt.mail, validateFunction.mail);
$("#mobileInfo").jdValidate(validatePrompt.mobileInfo, validateFunction.mobileInfo);
$("#mobileCode").jdValidate(validatePrompt.mobileCode, validateFunction.mobileCode);
$("#authcode").jdValidate(validatePrompt.authcode, validateFunction.authcode);

function emReg() {
    if (isSubmit) {
        return
    }
    isSubmit = true;
    $("#registsubmit").attr({ "disabled": "disabled" }).attr({ "value": "提交中,请稍等" });
    var passed = validateFunction.emReg_validate();
    //pageTracker._trackEvent('Button', 'Regist', 'Normal');
    if (passed) {
        var regUrl = "";
        var emtype = $("#emType").val();
        if (emtype == "email") {
            var uuid = $("#JD_Verification1").attr("src").split("&uid=")[1].split("&")[0];
            regUrl = "../emReg/emReg?rtype=personal&uuid=" + uuid + "&emType=email&emInfo=" + $("#mail").val();
        } else {
            regUrl = "../emReg/emReg?rtype=personal&emType=mobile&emInfo=" + $("#mobileInfo").val();
        }
        $.ajax({
            type: "POST",
            url: regUrl,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            data: $("#formpersonal").serialize(),
            success: function (result) {
                if (result) {
                    var obj = eval(result);
                    if (obj.info) {
                        changeVerc();
                        $("#registsubmit").removeAttr("disabled");
                        $("#registsubmit").attr({ "value": "同意以下协议，提交" });
                        alert(obj.info);

                        isSubmit = false;
                        return;
                    }
                    if (obj.noAuth) {
                        changeVerc();
                        window.location = obj.noAuth;
                        return;
                    }
                    if (obj.success == true) {
                        window.location = obj.dispatchUrl;
                    }
                }
            }
        });
    } else {
        $("#registsubmit").removeAttr("disabled");
        $("#registsubmit").attr({ "value": "同意以下协议，提交" });
        isSubmit = false;
    }
}
$("#authcode").bind('keyup', function (event) {
    if (event.keyCode == 13) {
        $("#registsubmit").click();
    }
});
$("#protocol").click(function () {
    if ($("#protocol").attr("checked") != true) {
        $("#registsubmitframe").attr({ "disabled": "disabled" });
    }
    else {
        $("#registsubmitframe").removeAttr("disabled");
    }
});